//
//  AppDelegate.m
//  USB_Reader
//
//  Created by xiaozao on 15/3/21.
//  Copyright (c) 2015年 Tony_Wang. All rights reserved.
//

#import "AppDelegate.h"
#import "MineViewController.h"
#import "MainViewController.h"
#import "NewsViewController.h"
#import "FunnyViewController.h"
#import "MYIntroductionView.h"
#import "MYIntroductionPanel.h"
@interface AppDelegate () <MYIntroductionDelegate>

@end

@implementation AppDelegate




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    MainViewController *mainVC = [[MainViewController alloc] init];
    NewsViewController *newsVC = [[NewsViewController alloc] init];
    FunnyViewController *funVC = [[FunnyViewController alloc] init];
    MineViewController *mineVC = [[MineViewController alloc] init];
    

    
    
    UINavigationController *mainNavVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
    UINavigationController *newsNavVC = [[UINavigationController alloc] initWithRootViewController:newsVC];
    UINavigationController *funNavVC = [[UINavigationController alloc] initWithRootViewController:funVC];
    UINavigationController  *mineNavVC = [[UINavigationController alloc] initWithRootViewController:mineVC];
    
    mainVC.tabBarItem.image = [UIImage imageNamed:@"book.png"];
    mainVC.title = @"阅读";
    
    newsVC.tabBarItem.image = [UIImage imageNamed:@"news.png"];
    newsVC.title = @"新闻";
    
    funVC.tabBarItem.image = [UIImage imageNamed:@"funny.png"];
    funVC.title = @"糗百";
    
    mineVC.tabBarItem.image = [UIImage imageNamed:@"mine.png"];
    mineVC.title = @"关于";
    
    UITabBarController *mainTabBarColltroller = [[UITabBarController alloc] init];
    mainTabBarColltroller.viewControllers = @[mainNavVC, newsNavVC, funNavVC, mineNavVC];
    mainTabBarColltroller.tabBar.backgroundColor = [UIColor blueColor];
    
    self.window.rootViewController = mainTabBarColltroller;
    
    
    //读取沙盒数据
    NSUserDefaults * settings1 = [NSUserDefaults standardUserDefaults];
    NSString *key1 = [NSString stringWithFormat:@"is_first"];
    NSString *value = [settings1 objectForKey:key1];
    
    
    
    if (!value)  //如果没有数据
    {
        //STEP 1 Construct Panels
        MYIntroductionPanel *panel = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:@"23.png"] title:@"" description:@"no"];
        
        //You may also add in a title for each panel
        MYIntroductionPanel *panel2 = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:@"info.png"] title:@"" description:@"no"];
        
        //STEP 2 Create IntroductionView
        
        /*A standard version*/
        //MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) headerImage:[UIImage imageNamed:@"SampleHeaderImage.png"] panels:@[panel, panel2]];
        
        
        /*A version with no header (ala "Path")*/
        //MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) panels:@[panel, panel2]];
        
        /*A more customized version*/
        MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height) headerImage:nil panels:@[panel, panel2] languageDirection:MYLanguageDirectionLeftToRight];
        [introductionView setBackgroundImage:[UIImage imageNamed:@"48.jpg"]];
        
        
        //Set delegate to self for callbacks (optional)
        introductionView.delegate = self;
        
        //STEP 3: Show introduction view
        [introductionView showInView:self.window];
        
        //写入数据
        NSUserDefaults * setting = [NSUserDefaults standardUserDefaults];
        NSString * key = [NSString stringWithFormat:@"is_first"];
        [setting setObject:[NSString stringWithFormat:@"false"] forKey:key];
        [setting synchronize];
        
        // 内存管理
        [panel release];
        [panel2 release];
        [introductionView release];
        
        
    }
    
    mainTabBarColltroller.tabBar.tintColor = [UIColor blackColor];
    
    [mineVC release];
    [funVC release];
    [newsVC release];
    [mainVC release];
    [mineNavVC release];
    [mainNavVC release];
    [funNavVC release];
    [newsNavVC release];
    [mainTabBarColltroller release];
    [_window release];
    return YES;
}
-(void)dealloc
{
    [_window release];
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
